<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <!--MyHeader-->
    <div th:include="common::MyHeader"></div>
    <!-- End of MyHeader -->

</head>

<body id="page-top">

<!-- Page Wrapper -->
<div id="wrapper">

    <!-- Sidebar -->
    <ul th:replace="common::Sidebar(${session.user.userName})"></ul>
    <!-- End of Sidebar -->

    <!-- Content Wrapper -->
    <div id="content-wrapper" class="d-flex flex-column">

        <!-- Main Content -->
        <div id="content">

            <!-- Topbar -->
            <div th:include="common::Topbar(${session.user.userName})"></div>
            <!-- End of Topbar -->

            <!-- Begin Page Content -->
            <div class="container-fluid">

                <!-- Page Heading -->
                <div class="d-sm-flex align-items-center justify-content-between mb-4">
                    <h1 class="h3 mb-0 text-gray-800"> 添加书架</h1>
                </div>


                <!-- Content Column -->
                <div class="form-row">
                    <div class="form-group col-lg-6">
                        <label for="className">书架类名</label>
                        <input type="text" class="form-control" id="className">
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group col-lg-3">
                        <label>评论区开闭</label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="comments" id="exampleRadios1" value="1" checked>
                        <label class="form-check-label" for="exampleRadios1">
                            打开
                        </label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="comments" id="exampleRadios2" value="0">
                        <label class="form-check-label" for="exampleRadios2">
                            关闭
                        </label>
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group col-lg-6">
                        <label for="layer">放置楼层</label>
                        <input id="layer" type="number">
                    </div>
                </div>

                <button id="subBtn" onclick="subBtnFun()">添加</button>


            </div>

        </div>
        <!-- /.container-fluid -->

    </div>
    <!-- End of Content Wrapper -->

</div>
<!-- End of Page Wrapper -->

<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
</a>

<!-- Logout Modal-->
<div th:include="common::LogoutModal"></div>


</body>

</html>
<script>
    function subBtnFun(){

        var bookshelfClassname=$('#className').val()
        var ifOpenComment=$("input[name='comments']:checked").val();
        var bookshelfLayer=$('#layer').val()

        if (bookshelfClassname!=""&&ifOpenComment!=""&&bookshelfLayer!=""){
            $.post(
                "/bookshelf/createBookshelf",
                {
                    bookshelfClassname:bookshelfClassname,
                    ifOpenComment:ifOpenComment,
                    bookshelfLayer:bookshelfLayer
                },
                function (response) {
                    if(response.code==0){
                        window.location.href="#";
                    }else {
                        alert(response.msg)
                    }

                }


            )
        }


    }
</script>